package com.wuhunyu.controller;


import com.wuhunyu.commonutils.result.CommonResult;
import com.wuhunyu.entities.vo.CourseInfoVo;
import com.wuhunyu.entities.vo.CourseVo;
import com.wuhunyu.query.EduCourseQuery;
import com.wuhunyu.service.EduCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author wuhunyu
 * @since 2021-01-17
 */
@RestController
@RequestMapping("/eduCourse")
//@CrossOrigin
public class EduCourseController {

    @Autowired
    private EduCourseService eduCourseService;

    @PostMapping("/addCourse")
    public CommonResult addCourse(@RequestBody(required = false) CourseInfoVo courseInfoVo) {
        return eduCourseService.addCourse(courseInfoVo);
    }

    @DeleteMapping("/{id}")
    public CommonResult deleteCourse(@PathVariable("id") String id) {
        return eduCourseService.deleteCourse(id);
    }

    @PutMapping("/updateCourse")
    public CommonResult updateCourse(@RequestBody(required = false) CourseInfoVo courseInfoVo) {
        return eduCourseService.updateCourse(courseInfoVo);
    }

    @GetMapping("/selectCourseInfo/{courseId}")
    public CommonResult selectCourseInfo(@PathVariable("courseId") String courseId) {
        return eduCourseService.selectCourseInfo(courseId);
    }

    @PutMapping("/updateStatus/{courseId}")
    public CommonResult updateStatus(@PathVariable("courseId") String courseId) {
        return eduCourseService.updateStatus(courseId);
    }

    @PostMapping("/selectCourses")
    public CommonResult selectCourses(@RequestBody(required = false) EduCourseQuery eduCourseQuery) {
        return eduCourseService.selectCourses(eduCourseQuery);
    }

    @GetMapping("/selectCourses")
    public CommonResult selectCourses() {
        return eduCourseService.selectCourses();
    }

    @PostMapping("/selectCoursesByCourseVo")
    public CommonResult selectCourses(@RequestBody(required = false) CourseVo courseVo) {
        return eduCourseService.selectCourses(courseVo);
    }

    @GetMapping("/selectCourseDetail/{courseId}")
    public CommonResult selectCourseDetail(@PathVariable("courseId") String courseId, HttpServletRequest request) {
        return eduCourseService.selectCourseDetail(courseId, request);
    }

    @PostMapping("/selectCourseForOrder/{courseId}")
    public CommonResult selectCourseForOrder(@PathVariable("courseId") String courseId) {
        return eduCourseService.selectCourseForOrder(courseId);
    }

    @PostMapping("/isCourse/{courseId}")
    public CommonResult isCourse(@PathVariable("courseId") String courseId) {
        return eduCourseService.isCourse(courseId);
    }

    @GetMapping("/selectCourseById/{courseId}")
    public CommonResult selectCourseById(@PathVariable("courseId") String courseId) {
        return eduCourseService.selectCourseById(courseId);
    }

    @PutMapping("/updateCourseStatus")
    public CommonResult updateCourseStatus(@RequestBody(required = false) String[] ids) {
        return eduCourseService.updateCourseStatus(ids);
    }

}

